package com.fand.context;

import java.util.HashMap;
import java.util.Map;

public class ContextHolder {
	private static final ThreadLocal<Map<String, String>> stringMapThreadLocal = new ThreadLocal<Map<String, String>>();
	private static final ThreadLocal<String> idThreadLocal = new ThreadLocal<String>();

	public static void clearId() {
		ContextHolder.idThreadLocal.remove();
	}

	public static void clearStringValue() {
		ContextHolder.stringMapThreadLocal.remove();
	}

	public static String getId() {
		return ContextHolder.idThreadLocal.get();
	}

	public static String getStringValue(final String key) {
		if (ContextHolder.stringMapThreadLocal.get() == null) {
			return null;
		}

		return ContextHolder.stringMapThreadLocal.get().get(key);
	}

	public static void setId(final String value) {
		ContextHolder.idThreadLocal.set(value);

	}

	public static void setStringValue(final String key, final String value) {
		if (ContextHolder.stringMapThreadLocal.get() == null) {
			ContextHolder.stringMapThreadLocal.set(new HashMap<String, String>());
		}

		ContextHolder.stringMapThreadLocal.get().put(key, value);
	}
}
